#ifndef VENUS_GRAPHICS_RENDERDEVICE_H
#define VENUS_GRAPHICS_RENDERDEVICE_H

#include "common/venus.h"
#include "opengl.h"
#include "framebuffer_object.h"

namespace venus {
class ImageTextureGL;
class RenderBuffer;
class RenderDeviceFBO {
 public:
  void Activate() { fbo_.Bind(); }
  void Deactivate() { FramebufferObject::Disable(); }
  void Check() { fbo_.IsValid(); }
  void SetRenderTarget(const ImageTextureGL *texture);
  void SetRenderTargets(int target_counts, 
                        const ImageTextureGL *const textures[]);
  void SetRenderTarget(const RenderBuffer *render_buffer);
  void SetRenderTargets(int target_counts, 
                        const RenderBuffer *const render_buffers[]);
  void SetDepthBuffer(const ImageTextureGL *texture);
  void SetDepthBuffer(const RenderBuffer *render_buffer);
  void DisableDepthBuffer();
  template<typename T>
  void AdjustViewport(const T *target) {
    glViewport(0, 0, target->width(), target->height());
  }
  /*
   * there may be problem in the case of multiple render targets,
   * if simply disable frame buffer object, maybe here should record them
   * and detach them when necessary, for example, when target_count exceeds
   * the target_count in last call to SetRenderTargetGL
   */
  void SaveMVP();
  void RestoreMVP();
 private:
  FramebufferObject fbo_;
  static GLint s_viewport[4];
};
} // namespace venus

#endif // VENUS_GRAPHICS_RENDERDEVICE_H
